<?php
namespace app\index\controller;
use think\Db;
use think\Controller;
use think\Request;
class Common extends Controller
{

    public function __construct(){
        parent::__construct();
        $action = Request::instance()->action();
        header('Location: /admin');
//        print_r(Request::instance());



        $PHP_SELF = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : (isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] : $_SERVER['ORIG_PATH_INFO']);
        $PHP_URL=basename($PHP_SELF);


        $id=input('id',0);
        $pid=input('pid',0);
        $ty=input('ty',0);
        $tty=input('tty',0);
        $ttty=input('ttty',0);
        $Custitle="";
        $Title="";
        $Seotitle="";
        if($id){
            $table="news";

            $bd=db($table)->where("status=1 AND id={$id}")->find();
            if($bd){
                $id=$id;
                $vpid=$bd['pid'];
                $vty=$bd['ty'];
                $vtty=$bd['tty'];
                $vttty=$bd['ttty'];
                $Title=$bd['title'];
                $Ftitle=$bd['ftitle'];
                $Seotitle=$bd['seotitle'];
                $Seokeywords=$bd['seokeywords'];
                $Seodescription=$bd['seodescription'];
                $Content=get_html($bd['content']);
                $Hits=get_html($bd['hits']);
            }
        }elseif($pid&&$id==0){
            if($ty) $zid=$ty; else $zid=get_nextid($pid);

            $vtty=$tty;
            $vttty=$ttty;


            $bd=Db::name('sort')->field("catname,seotitle,seokeywords,img1,seodescription")->where("status=1 AND id={$zid}")->find();
            //$bd=Db::name('sort')->where("status=1 AND id={$zid}")->find();
            //print_r($bd);die;
            if($bd){
                if($pid) $vpid=$pid;

                if($ty) $vty=$ty;else $vty=$zid;
                $Title=$bd['catname'];
                $Seotitle=$bd['seotitle'];
                $Seokeywords=$bd['seokeywords'];
                $Seodescription=$bd['seodescription'];
            }

            //print_r($bd);
        }elseif($id==0){
            $vpid=0;
            $Seotitle=sys('sys_seotitle');
            $Seotitle=sys('sys_seotitle');
            $Seokeywords=sys('sys_seokeywords');
            $Seodescription=sys('sys_seodescription');
        }

        if($Custitle){
            $Seotitle=$Custitle;
        }else{
            if($Title) $Seotitle=$Title."_".$Seotitle;
            elseif($Seotitle) $Seotitle=$Seotitle;
            else $Seotitle="";
        }
        $user_id=session('user_id');
        $this->assign("Seotitle",$Seotitle);
        $this->assign("Seokeywords",$Seokeywords);
        $this->assign("Seodescription",$Seodescription);
        $this->assign("id",$id);
        $this->assign("vpid",$vpid);
        $this->assign("vty",$vty);
        $this->assign("vtty",$vtty);
        $this->assign("user_id",$user_id);
        $this->assign("action",$action);
    }


    public function check_login(){
        $user_id=session("user_id");
        if(!$user_id){
            $this->error("请登录","/index/login/login.html");
        }
    }
}
